<!DOCTYPE html>
<!--
TODO(yosin): We should upstream to wpt test.
This file is taken from https://github.com/kojiishi/web-platform-tests/blob/53908d773012edf931047674f7afe3975bc1820f/custom-elements/custom-elements-registry/get.html
-->
<title>Custom Elements: CustomElementRegistry.get</title>
<script src="../../../resources/testharness.js"></script>
<script src="../../../resources/testharnessreport.js"></script>
<body>
<div id="log"></div>
<script>
'use strict';
(() => {
  // https://html.spec.whatwg.org/multipage/scripting.html#dom-customelementregistry-whendefined
  // Use window from iframe to isolate the test.
  function setup() {
    const iframe = document.createElement('iframe');
    document.body.appendChild(iframe);
    const testWindow = iframe.contentWindow;
    const customElements = testWindow.customElements;
    if (!customElements)
      return Promise.reject('This test requires window.customElements');
    if (!('get' in customElements))
      return Promise.reject('This test requires window.customElements.get');
    return Promise.resolve(customElements);
  }

  promise_test(() => setup()
    .then(customElements => {
      // 1. If this CustomElementRegistry contains an entry with name name,
      // then return that entry's constructor.
      const name = 'test-get-existing';
      class C extends HTMLElement {};
      customElements.define(name, C);
      assert_equals(customElements.get(name), C, 'get() returns the constructor')
      return Promise.resolve(customElements);
    }).then(customElements => {
      // 2. Otherwise, return undefined.
      assert_equals(customElements.get('test-get-not-defined'), undefined,
                    'get() returns undefined for not-defined name');
    }).catch(reason => { throw reason }));
})();
</script>
</body>
